package cn.sixmillioins.jvm;


import sun.misc.Launcher;

import java.net.URL;

/**
 * 类加载器
 *
 * @author sixmillions
 */
public class D002JdkClassLoader {

    public static void main(String[] args) {
        //rt.jar包下的基础类
        System.out.println(String.class.getClassLoader());
        //ext目录下sunjce_provider.jar的内的某个类(jdk1.8)
        System.out.println(com.sun.crypto.provider.DESKeyFactory.class.getClassLoader());
        //当前类的加载器
        System.out.println(D002JdkClassLoader.class.getClassLoader());

        System.out.println();

        ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassLoader = appClassLoader.getParent();
        ClassLoader bootstrapLoader = extClassLoader.getParent();
        System.out.println("系统默认加载器：" + appClassLoader);
        System.out.println("AppClassLoader的父加载器：" + extClassLoader);
        //ExtClassLoader父加载器是引导类加载器，c++实现，看不到，源码中也是null
        System.out.println("ExtClassLoader的父加载器：" + bootstrapLoader);

        System.out.println();

        System.out.println("bootstrapLoader（引导类加载器）加载了以下文件：");
        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
        for (URL urL : urLs) {
            System.out.println(urL);
        }

        System.out.println();

        System.out.println("ExtClassLoader加载了以下文件：");
        System.out.println(System.getProperty("java.ext.dirs"));

        System.out.println();

        System.out.println("AppClassLoader加载了以下文件：");
        System.out.println(System.getProperty("java.class.path"));
    }
}
